package com.sdruixinggroup.mondayb2b.ui.fragments;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.google.gson.reflect.TypeToken;
import com.sdruixinggroup.mondayb2b.API.API;
import com.sdruixinggroup.mondayb2b.R;
import com.sdruixinggroup.mondayb2b.interfaces.ObjectCallBack;
import com.sdruixinggroup.mondayb2b.models.MessagetBeen;
import com.sdruixinggroup.mondayb2b.models.ModelBeen;
import com.sdruixinggroup.mondayb2b.utils.UserInfoUtil;
import com.zhy.http.okhttp.OkHttpUtils;

import java.util.HashMap;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import okhttp3.Call;

import static com.sdruixinggroup.mondayb2b.R.id.tv_time;
import static com.sdruixinggroup.mondayb2b.R.id.tv_title_m;

/**
 * Created by 00029935 on 2017/11/18.
 */

public class SystemInforFragment extends BaseFragment {
    @BindView(R.id.ib_back)
    ImageView ibBack;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(tv_title_m)
    TextView tvTitleM;
    @BindView(tv_time)
    TextView tvTime;
    @BindView(R.id.tv_content)
    TextView tvContent;
    @BindView(R.id.iv_good_pic)
    ImageView ivGoodPic;
    private MessagetBeen.MessagesBean.DataBean data;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        data = (MessagetBeen.MessagesBean.DataBean) getActivity().getIntent().getSerializableExtra("object");
    }

    @Override
    protected int getInflateLayout() {
        return R.layout.system_infor_fragment;
    }

    @Override
    protected void setUpView(View view) {
        tvTitle.setText("详情");
        tvTitleM.setText(data.getTitle());
        tvTime.setText("发布时间  " + data.getCreated_time());
        Glide.with(getContext()).load(data.getPic()).into(ivGoodPic);
        tvContent.setText(data.getContent());
        read(data.getMessage_id());
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        ButterKnife.bind(this, rootView);
        return rootView;
    }

    @OnClick(R.id.ib_back)
    public void onClick() {
        getActivity().finish();
    }

    private void read(int id){
        String url = API.MESSAGE+id+"/read?"+"&access_token="+ UserInfoUtil.getInfoToken(getContext());
        HashMap<String, String> heades = new HashMap<>();
        heades.put("Accept", "*/*");

        TypeToken<ModelBeen> typeToken = new TypeToken<ModelBeen>() {
        };

        OkHttpUtils.get().url(url).headers(heades).build().execute(new ObjectCallBack<ModelBeen>(typeToken) {
            @Override
            public void onError(Call call, Exception e, int id) {

            }

            @Override
            public void onResponse(ModelBeen response, int id) {


            }
        });
    }
}
